﻿@{
    Layout = "~/Views/Shared/_level2.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
        <script src="~/LiberUI/Scripts/laytpl.js"></script>
    }
}
<title>采购应用-订单</title>
<link href="/SiteUI/Purchase/share.css" rel="stylesheet" />
<link href="/SiteUI/Purchase/Orders.css" rel="stylesheet" />
<link href="/SiteUI/bootstrap-datepicker3.css" rel="stylesheet" />
@section contentnavi{
<div id="appTitle">
    采购应用
</div>
<ul id="slideNavi">
    <li><a class="Lite" href="/Purchase/Inquriy"><i class="icon-063coinyen"></i>询&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价<i class="icon-navigatenext arrow-go"></i></a></li>
    <li class="naviGroup">
        <span>采购订单</span>
        <a class="Lite" href="/Purchase/Orders"><i class="icon-svgorderred"></i>部门订单<i class="icon-navigatenext arrow-go"></i></a>
        <a class="Lite" href="/Purchase/MyOrders"><i class="icon-svgorderred"></i>我的订单<i class="icon-navigatenext arrow-go"></i></a>
    </li>
    <li><a class="Lite" href="/Purchase/Receipt"><i class="icon-jinhuo"></i>收&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;货<i class="icon-navigatenext arrow-go"></i></a></li>
</ul>
}
<div class="col-lg-5 col-lg-offset-6 searchboxWraper">
    <!--搜索框组件容器-->
</div>


<div class="col-lg-10 col-lg-offset-1" id="Orders">
    <div class="row" id="lstOrders">
        <div class="col-lg-12 head">
            <h4>我的订货单</h4>
            <span class="cnd-status" status='' desc="orderdate">全部</span>
            <span class="cnd-status" status='draft' desc="orderdate">待发送</span>
            <span class="cnd-status" status='pending' desc="orderdate">待确认</span>
            <span class="cnd-status" flag='toDelivery' asc='dlvdate'>待发货</span>
            <span class="cnd-status" flag='toStockIn' asc='dlvdate'>待入库</span>
            <span class="" flag='toPay' desc="orderdate">待付款</span>
            <span class="more-filter" id="more-filter">更多筛选条件</span>
        </div>
        <form class="col-lg-12 more-filter-box" id="more-filter-box">
            <button class="more-filter-close" id="more-filter-close" type="button"><i class="soicon icon-highlightremove"></i></button>
            <div class="filter-item">
                <span class="label">供&nbsp;应&nbsp;商：</span>
                <label class="input-box col-lg-12"><input class="input" type="text" name="client"></label>
            </div>
            <div class="filter-item">
                <span class="label">使用单位：</span>
                <label class="input-box col-lg-12"><input class="input" type="text" name="constructor"></label>
            </div>
            <div class="filter-item">
                <span class="label">订货日期：</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="orderDateStart"></label>
                <span class="col-lg-2">至</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="orderDateEnd"></label>
            </div>
            <div class="filter-item">
                <span class="label">交货日期：</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="dlvDateStart"></label>
                <span class="col-lg-2">至</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="dlvDateEnd"></label>
            </div>
            <div class="filter-item">
                <button class="filter-search button">筛&nbsp;&nbsp;选</button>
            </div>
        </form>
        <div class="col-lg-12" id="cnd-quick">
            <div class="row">
                <div class="col-lg-4">
                    &nbsp;快速筛选：<div class="dropdown" id="cnd-quick-ordDate" ordDate="all">订货日期：全部</div>
                </div>
            </div>
        </div>
        <div class="col-lg-12" id="pch-lstOrders">

        </div>
        <div class="col-lg-12" id="pch-lstOrders-Paging"></div>
    </div>
</div>

<ul class="cnd-item" id="cnd-item-ordDate">
    <li ordDate="thisWeek">本周</li>
    <li ordDate="preWeek">上周</li>
    <li ordDate="thisMonth">本月</li>
    <li ordDate="all">全部</li>
</ul>


<script id="tplPchOrder" type="text/html">
    <div class="row noItem" objid="{{d.idstr}}">
        <div class="col-lg-1 no-row-head">
            <img src='{{d.supplier_logo}}' />  <!--供应商Logo-->
        </div>
        <div class="col-lg-11 no-row-body">
            <div class="row no-headline">
                <div class="col-lg-4 no-tradeno">
                    <span>交易编号：</span><span>{{d.idstr}}</span>
                </div>
                <div class="col-lg-5 no-supplier">
                    <span class="Company {{(d.supplier_id)?'certificated':'no-certificated'}}"><i class="soicon icon-004office"></i>&nbsp;{{d.supplier}}</span>
                </div>
                <div class="col-lg-3 no-lnks">
                    <a class="LinkTo" target="_blank" href="/Trade/OrderDetail?oid={{d.idstr}}">查看详情>></a>
                </div>
            </div>
            <div class="row no-describe">
                <div class="col-lg-4">
                    <span>内部订单：</span><span>{{d.src_orderserial}}[{{d.src_orderversion||'-'}}]</span>
                    <br />
                    <span>订货日期：</span><span>{{d.orderdate}}</span>
                    <br />
                    <span>采购经办：</span>
                    <a class="People {{d.buyer_id?'certificated':'no-certificated'}}"><img src="{{d.buyer_headimg}}" />{{d.buyer}}</a>
                    <br />
                </div>
                <div class="col-lg-4 withLeftIndent">
                    <span>订单金额：</span><span><strong>{{d.amountStr}}</strong></span>
                    <br />
                    {{#if(d.urgent==true){ }}
                    <span>交货日期：</span><span class="urgent" title="交货日期已临近，请注意跟进">{{d.deliverydate}}<i class="icon-erroroutline"></i></span>
                    {{#}else{ }}
                    <span>交货日期：</span><span>{{d.deliverydate}}</span>
                    {{#} }}
                    <br />
                    <span>销售经办：</span><a class="People {{d.saler_id?'certificated':'no-certificated'}}" objid="{{d.saler_id}}"><img src='{{d.saler_headimg||'/UserFile/DefaultUserLogo-nocertificated.png'}}'/>{{d.saler||d.src_saler}}</a>
                    <br />
                </div>
                <div class="col-lg-4 withLeftIndent">
                    <span>已发货：</span><span>{{d.totaldelivery||'-'}}{{d.dlvPercent}}</span>
                    <br />
                    <span>已入库：</span><span>{{d.totalstockin||'-'}}{{d.stockinPercent}}</span>
                    <br />
                    <span>已付款：</span><span>-</span>
                    <br />
                </div>
            </div>
        </div>
    </div>
</script>

<script src="/LiberUI/Scripts/moment.js"></script>
<script src="/LiberUI/Scripts/bootstrap-datepicker.js"></script>
<script src="/LiberUI/Scripts/laytpl.js"></script>
<script>
    var pchOrders = {
        orders: [],
        cnd: {
            onlymine: true,
            status: "all",
            flag: null,
            ordDate: null,
            ordDateStart: null,
            ordDateEnd: null,
            dlvDate: null,
            dlvDateStart: null,
            dlvDateEnd: null,
            supplier: null,
            buyer: null,
            useunit: null,
            orgid: -1,
            desc: 'orderdate',
            asc: '',
            page: 0,
            num: 20
        },
        tplOrder: null,
        lstOrders: null,
        remindSaler: function (ev) {
            var btn = $(this).eq(0);
            if (btn.hasClass('disabled')) {
                return;
            }
            btn.addClass("disabled").vl("<i class='soicon icon-done'>已发送提醒</i>");
            var oid = btn.parents(".newOrder").eq(0).attr("orderid");
            $.getJSON("/Purchase/RemindSaler?oid=" + oid, null, null);
        },
        makeOrderView: function ($item, od) {
            od.supplier_logo = od.supplier_logo || "/UserFile/DefaultCompanyLogo.gif";
            od.supplier = od.supplier_realname || od.src_supplier;
            od.consignee_certify = od.consignee ? 'certificated' : 'no-certificated';
            od.saler = od.saler || od.src_saler;
            od.consignee_displayname = od.src_consignee || od.consignee_realname;
            od.consignee_headimg = od.consignee_headimg || od.consignee ? "/UserFile/DefaultUserLogo.png" : "/UserFile/DefaultUserLogo-nocertificated.png"
            od.orderdate = new Date(od.src_orderdate || od.createtime).toString();
            od.deliverydate = new Date(od.src_deliverydate || od.deliverydate).toString();

            od.amountStr = od.amount.roundTo(2).toThousands();
            od.taxrate = od.taxrate + "%";
            if (pchOrders.cnd.flag == 'toDelivery' || pchOrders.cnd.flag == 'toStockIn') {
                od.urgent = daysBetween(new Date(od.src_deliverydate || od.deliverydate).toString(), new Date().toString()) < 5;
            }
            od.dlvPercent = od.totaldelivery ? ('<em>[' + (od.totaldelivery / od.amount).formatPercent(2) + ']</em>') : '';
            od.stockinPercent = od.totalstockin ? ('<em>[' + (od.totalstockin / od.amount).formatPercent(2) + ']</em>') : '';
            var v = $(pchOrders.tplOrder.render(od)).addClass("fladeInUp");

            if (od.status == 'Pending' && od.src_orderversion && od.src_orderversion.split('-')[1] != '01') {
                v.addClass("withHistory");
            }

            v.appendTo($item);
        },
        onGetOrdersEnd: function (rtn) {
            if (rtn.IsPositive) {
                pchOrders.orders = rtn.Data.Orders;
                pchOrders.lstOrders.vl(rtn.Data.Orders)
                                   .update()
                                   .show();
            }
        },
        Query: function (recount) {
            var cFlag = $(".cnd-status.current");
            var status = cFlag.attr("status");
            var flag = cFlag.attr("flag");
            pchOrders.cnd.status = status || "";
            pchOrders.cnd.flag = flag || "";
            pchOrders.cnd.desc = cFlag.attr("desc") || "";
            pchOrders.cnd.asc = cFlag.attr("asc") || "";
            var pd = $("#cnd-quick-ordDate").attr("ordDate");
            pchOrders.cnd.ordDate = pd;

            if (recount) {
                pchOrders.cnd.page = 1;
                $.getJSON("/Purchase/CountOrders", pchOrders.cnd, pchOrders.onCountEnd);
            }
            $.getJSON("/Purchase/QueryOrders", pchOrders.cnd, pchOrders.onGetOrdersEnd);

            pchOrders.lstOrders.vl(null)
                   .update()
                   .Loading("正在加载...");
        },
        onCountEnd:function(rtn){
            if (rtn.IsPositive) {
                pchOrders.paging.option("Total", rtn.Data.Total)
                                .option("CurrPage", 1)
                                .update();
            }
        },
        GoPage: function (pg) {
            pchOrders.cnd.page = pg;
            pchOrders.Query();
        },
        popCndOrderDate: null,
        popCndDlvDate: null,
        paging:null
    };

    $(function () {
        var navis = $("#slideNavi>li>a");
        for (var i = 0; i < navis.length; i++) {
            if (navis.eq(i).attr("href") == window.location.pathname) {
                navis.eq(i).addClass("current");
                break;
            }
        }
        $(".Searcher").appendTo(".searchboxWraper").fadeIn();
        pchOrders.tplOrder = laytpl($("#tplPchOrder")[0].innerHTML);  //定义模板实例
        pchOrders.lstOrders = new LiberUI.Lister("#pch-lstOrders")
                                         .option("Slctble", false)
                                         .option("ContentRender", pchOrders.makeOrderView)
                                         .Empty("没有符合条件的记录");
        pchOrders.paging = new LiberUI.Paging("#pch-lstOrders-Paging")
            .option("Row", 20)
            .option("BtnClick", pchOrders.GoPage)
            .show();

        pchOrders.popCndOrderDate = new LiberUI.PopPanel("#cnd-item-ordDate")
                                         .PopFor("#cnd-quick-ordDate");

        $("#lstOrders>.head").delegate(".cnd-status", "click", function (ev) {
            $("#lstOrders").find(".current").removeClass("current");
            $(ev.currentTarget).addClass("current");
            pchOrders.Query(true);
        });

        $("#cnd-item-ordDate").delegate("li", "click", function (ev) {
            $("#cnd-quick-ordDate").vl("订货日期：" + $(this).vl())
                                   .attr("ordDate", $(this).attr("ordDate"));

            pchOrders.popCndOrderDate.hide();
            pchOrders.Query(true);
        });

        pchOrders.cnd.flag = getUrlParam("flag");
        pchOrders.cnd.status = getUrlParam("status") || "pending";

        var defFlag = $(".cnd-status[flag='" + pchOrders.cnd.flag + "']");
        if (defFlag.length > 0) {
            defFlag.addClass("current");
        }
        else {
            defFlag = $(".cnd-status[status='" + pchOrders.cnd.status + "']");
            if (defFlag.length > 0) {
                defFlag.addClass("current");
            }
            else {
                $(".cnd-status[status='pending']").addClass("current");
            }
        }
        pchOrders.Query(true);


        /*  16/7/28 更多筛选条件 */
        function fillSubmitData(data) {
            pchOrders.cnd.supplier = data.eq(0).val();
            pchOrders.cnd.useunit = data.eq(1).val();
            pchOrders.cnd.orderDateStart = data.eq(2).val();
            pchOrders.cnd.orderDateEnd = data.eq(3).val();
            pchOrders.cnd.dlvDateStart = data.eq(4).val();
            pchOrders.cnd.dlvDateEnd = data.eq(5).val();
        }
        $('#more-filter-box .date-picker input').datepicker({
            autoclose: true,
            todayHighlight: true,
            format:'yyyy-mm-dd'
        });
        $('#more-filter').on('click', function () {
            var status = $(this).hasClass('more-filter-open');
            if (status == true) {

                //如果已经展开，触发关闭按钮效果
                $('#more-filter-close').trigger('click');
                return;
            }

            //获取原始高度
            var box = $('#more-filter-box'), boxHeight = box.css('height', 'auto').height();

            //恢复0高度以便动画进行
            box.css('height', '0');

            $(this).addClass('more-filter-open');
            $('#more-filter-box').stop().animate({ height: boxHeight + 20 }, 500); // 20为 more-filter-box padding
        });
        $('#more-filter-close').on('click', function (e) {
            e.preventDefault();
            $('#more-filter-box').stop().animate({ height: 0 }, 500);
            $('#more-filter').removeClass('more-filter-open');

            //清空输入项
            var inputs = $('#more-filter-box').find('input');
            inputs.val('');
            fillSubmitData(inputs);
        });
        $('#more-filter-box').on('submit', function (e) {
            e.preventDefault();

            //筛选条件提交
            fillSubmitData($(this).find('input'));

            pchOrders.Query(true);
        });
    });
</script>